package sg.edu.nus.iss.jass.gui;

import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JButton;
import sg.edu.nus.iss.jass.constant.ActionBtnContants;
import sg.edu.nus.iss.jass.util.Util;

/**
 * <h5>DefaultActionPanel to load the deafult action buttons on the actual GUI form </h5>
 * This   class is derived from ActionPanel to create the deafult action buttons using Swing JButtons.
 * This class will create three buttons namely "Add", "Reset" and "Cancel" if the default constructor
 * from DefaultActionPanel is called.
 * Otherwise, the developers will be able to create the buttons by passing the array of Buttons String of their choice
 * by calling the other constructor.
 * @author Kafoor Sammil
 * 
 */

public class DefaultActionPanel extends ActionPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8824543610553425117L;

	/**
     * The Array List of Buttons .
     */ 
	private List<JButton> btns = new ArrayList<JButton>();
	
	
	/**
     * Constructor to create the default buttons panel namely  "Add", "Reset" and "Cancel".
     */ 
	public DefaultActionPanel() {
		this(ActionBtnContants.ADD, ActionBtnContants.RESET, ActionBtnContants.CANCEL);
	}
	
	
	/**
     * Constructor to create the default buttons panel by passing array of button names .
     */ 
	public DefaultActionPanel(String ... btnNames) {
		super();
		
		for ( int i =0;i<btnNames.length;i++){
			if(!Util.isEmpty(btnNames[i])) {
			JButton btn = new JButton(btnNames[i]);
				this.add(btn);
				this.btns.add(btn);
			}
		}
		
	}
	
	/**
	 *  Method to register the event with the action listener. 
	 *  This method is called from the FormPanel for registering the action buttons on ActionPanel.
	 * @param actionListener
	 *            the listener interface for receiving action events. 
	 */
	public void addActionListener(ActionListener actionListener){
		for ( JButton btn:btns){
			btn.addActionListener(actionListener);
		}
	}
	
}
